return libxl_device_del(ctx, &device, wait);
}
+void libxl_free_nics_list(libxl_nicinfo *nics, unsigned int nb)
+{
+ unsigned int i;
+ for(i = 0; i < nb; i++) {
+ free(nics[i].backend);
+ free(nics[i].frontend);
+ free(nics[i].script);
+ }
+ free(nics);
+}
+
libxl_nicinfo *libxl_list_nics(libxl_ctx *ctx, uint32_t domid, unsigned int *nb)
{
char *dompath, *nic_path_fe;
- char **l;
+ char **l, **list;
char *val, *tok;
unsigned int nb_nics, i;
libxl_nicinfo *res, *nics;
if (!dompath) {
return NULL;
}
- l = libxl_xs_directory(ctx, XBT_NULL,
+ list = l = libxl_xs_directory(ctx, XBT_NULL,
libxl_sprintf(ctx, "%s/device/vif", dompath), &nb_nics);
if (!l) {
return NULL;
}
- res = libxl_calloc(ctx, nb_nics, sizeof (libxl_device_nic));
+ nics = res = calloc(nb_nics, sizeof (libxl_device_nic));
if (!res) {
libxl_free(ctx, l);
return NULL;
}
- nics = res;
for (*nb = nb_nics; nb_nics > 0; --nb_nics, ++l, ++nics) {
nic_path_fe = libxl_sprintf(ctx, "%s/device/vif/%s", dompath, *l);
- nics->backend = libxl_xs_read(ctx, XBT_NULL,
- libxl_sprintf(ctx, "%s/backend", nic_path_fe));
+ nics->backend = xs_read(ctx->xsh, XBT_NULL,
+ libxl_sprintf(ctx, "%s/backend", nic_path_fe), NULL);
val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/backend-id", nic_path_fe));
nics->backend_id = val ? strtoul(val, NULL, 10) : -1;
nics->rref_tx = val ? strtol(val, NULL, 10) : -1;
val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/rx-ring-ref", nic_path_fe));
nics->rref_rx = val ? strtol(val, NULL, 10) : -1;
- nics->frontend = libxl_xs_read(ctx, XBT_NULL,
- libxl_sprintf(ctx, "%s/frontend", nics->backend));
+ nics->frontend = xs_read(ctx->xsh, XBT_NULL,
+ libxl_sprintf(ctx, "%s/frontend", nics->backend), NULL);
val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/frontend-id", nics->backend));
nics->frontend_id = val ? strtoul(val, NULL, 10) : -1;
- nics->script = libxl_xs_read(ctx, XBT_NULL,
- libxl_sprintf(ctx, "%s/script", nics->backend));
-
- libxl_free(ctx, nic_path_fe);
+ nics->script = xs_read(ctx->xsh, XBT_NULL,
+ libxl_sprintf(ctx, "%s/script", nics->backend), NULL);
}
- libxl_free(ctx, l);
return res;
}
int libxl_mac_to_device_nic(libxl_ctx *ctx, uint32_t domid,
const char *mac, libxl_device_nic *nic)
{
- libxl_nicinfo *nics;
- unsigned int nb, i;
+ libxl_nicinfo *nics, *list;
+ unsigned int nb, i, j;
uint8_t mac_n[6];
uint8_t *a, *b;
const char *tok;
char *endptr;
- nics = libxl_list_nics(ctx, domid, &nb);
+ list = nics = libxl_list_nics(ctx, domid, &nb);
if (!nics) {
return ERROR_FAIL;
}
}
}
memset(nic, 0, sizeof (libxl_device_nic));
- for (; nb; --nb, ++nics) {
+ for (j = 0; j < nb; ++j, ++nics) {
for (i = 0, a = nics->mac, b = mac_n;
(b < mac_n + 6) && (*a == *b); ++a, ++b)
;
nic->devid = nics->devid;
memcpy(nic->mac, nics->mac, sizeof (nic->mac));
nic->script = nics->script;
- libxl_free(ctx, nics);
+ libxl_free_nics_list(list, nb);
return 0;
}
}
- libxl_free(ctx, nics);
+ libxl_free_nics_list(list, nb);
return 0;
}
nic_path_be = libxl_xs_read(ctx, XBT_NULL,
libxl_sprintf(ctx, "%s/backend", nic_path_fe));
val = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/backend-id", nic_path_fe));
+ if ( NULL == val ) {
+ return ERROR_FAIL;
+ }
nic->backend_domid = strtoul(val, NULL, 10);
nic->devid = strtoul(devid, NULL, 10);
libxl_free(ctx, val);
int main_networklist(int argc, char **argv)
{
int opt;
- libxl_nicinfo *nics;
- unsigned int nb;
+ libxl_nicinfo *nics, *list;
+ unsigned int nb, i;
if (argc < 3) {
help("network-list");
fprintf(stderr, "%s is an invalid domain identifier\n", *argv);
continue;
}
- if (!(nics = libxl_list_nics(&ctx, domid, &nb))) {
+ if (!(list = nics = libxl_list_nics(&ctx, domid, &nb))) {
continue;
}
- for (; nb > 0; --nb, ++nics) {
+ for (i = 0; i < nb; ++i, ++nics) {
/* Idx BE */
printf("%-3d %-2d ", nics->devid, nics->backend_id);
/* MAC */
nics->devid, nics->state, nics->evtch,
nics->rref_tx, nics->rref_rx, nics->backend);
}
+ libxl_free_nics_list(list, nb);
}
return 0;
}